 $(function () {

        let ul_list_lis = document.querySelectorAll(".ul-list li ")
        let all_list = document.querySelector(".all-list")
        let category_counts = document.querySelectorAll(".category .count")
        for (let i = 0; i < ul_list_lis.length - 2; i++) {
            ul_list_lis[i].onmouseover = function () {
                category_counts[i].innerHTML += youxibijiben.map(item =>
                    ` <div class="box">
                     <img src="${item.src}" alt="">
                     <p>${item.title}</p>
                     <span>${item.price}</span>
                </div>`
                ).join("")
                category_counts[i].style.display = "block"
            }
            ul_list_lis[i].onmouseout = function () {
                category_counts[i].innerHTML = ""
                category_counts[i].style.display = "none"
            }


        }
        //分页器

        var swiper = new Swiper('.swiper-container', {
            spaceBetween: 30,
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            loop: true,
        });
        //懒加载
        $("img").lazyload()
        // console.log($("img"));
        is_user()
        
        
    
        // 楼梯

        let side_bar = $(".side_bar")
        let top_list = []
        //标记动画的状态
        let flag = false

        $(".side_bar li").click(function () {
            change_class.call(this)
            //获取对应元素的下标
            let index = $(this).index(".side_bar li")
            flag = true
             change_scrolltop(index)

        })
        //楼梯切换类名
        function change_class() {
            $(this).addClass("active").siblings().removeClass("active")
        }
        //点击按钮楼层显示
        function change_scrolltop(index) {

            // if (index > $(".side_bar li").length - 1) {
            //     return
            // } else {
            // }
                $("html,body")
                    .stop(true)
                    .animate({
                        scrollTop: top_list[index]+2
                    }, function () {
                        flag = false
                    })

        }

        //记录需要显示楼层的top值
        let first_floor = $(".first_floor")
        let second_floor = $(".second_floor")
        let third_floor = $(".third_floor")

        //一楼数据
        top_list.push(parseInt(first_floor.offset().top))
        //二楼数据
        top_list.push(parseInt(second_floor.offset().top))
        //三楼数据
        top_list.push(parseInt(third_floor.offset().top))
        console.log(top_list);


        //侧边栏显示隐藏，闭包节流
        $(window).scroll((function () {
            let t = null
            return function () {
                if (typeof t === "number") {
                    return false
                }
                t = setTimeout(function () {
                    t = null
                    let scrollTop = $("html,body").scrollTop()
                    // console.log(scrollTop);
                    scrollTop > 500 ? side_bar.css({ display: "block" }) : side_bar.css({ display: "none" })

                    if (!flag) {
                        let index = getIndex()
                        class_li(index)
                    }

                }, 50)
            }
        })())


        //根据页面滚动值获取下标
        function getIndex() {
            let scrollTop = $("html,body").scrollTop()
            if (scrollTop >= top_list[top_list.length - 1]) {
                return top_list.length - 1
            }

            for (let i = 0; i < top_list.length; i++) {
                if (scrollTop >= top_list[i] && scrollTop < top_list[i + 1]) {
                    return i
                }
            }


        }
        //获取一个最大值，删除活动类名
        let max_top = parseInt($(".max_floor").offset().top)
        //页面滚动范围给楼层图标添加类名
        function class_li(index) {
            let scrollTop = $("html,body").scrollTop()
            if (scrollTop >= max_top) {
                $(".side_bar li").removeClass("active")
            } else {
                $(".side_bar li").removeClass("active").eq(index).addClass("active")
            }

        }
        //回到顶部
        $(".out").click(function () {
            $(this).addClass("fixed")
            $("html,body")
                .animate({
                    scrollTop: 0
                }, 2000)
        })
        $(window).trigger("scroll")


    })